using System;
using System.Collections.Generic;
using System.Text;
using PH.Common;

namespace Hoshimi
{
    public class FollowBot_MoveState : State
	{
		#region Singleton

		// Fields
		protected static FollowBot_MoveState instance;

		// Constructor
		protected FollowBot_MoveState() : base() { }

		// Methods
		public static FollowBot_MoveState Instance()
		{
			// Uses "Lazy initialization"
			if( instance == null ) 
				instance = new FollowBot_MoveState();

			return instance;
		}

		#endregion

		public override bool Play( Unit unit ) 
        {
			FollowBot bot = (FollowBot) unit;

            bot.SetName("Follow");

            // We cant give order to the bot. We stop
			if ( bot.State != NanoBotState.WaitingOrders && bot.State != NanoBotState.Moving )
			{
				return true;
			}

            if (bot.UpdateDestination())
            {
                bot.StopIfMoving();
            }

            // We can't give orders to the bot. We stop
			if ( bot.State == NanoBotState.Moving) 
			{
				return true;
			}

            bot.MoveToDestination();
			return true;
		}
	}
}
